/**
* 基础菜单 商品管理
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>非结构化数据管理</el-breadcrumb-item>
    </el-breadcrumb>

    <!--    一个大大框 -->
    <div class="container">
      <h1>非结构化数据源列表</h1>
    </div>

    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="文件类别">
        <el-select
          v-model="formInline.tagId"
          placeholder="请选择分类"
          size="small"
        >
          <el-option
            v-for="(item, index) in typeOptions"
            :key="item.id"
            :label="item.tag"
            :value="item.id"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
          >搜索</el-button
        >
        <el-button
          size="small"
          type="primary"
          icon="el-icon-refresh"
          @click="reset"
          >重置</el-button
        >
      </el-form-item>

      <!--      <el-form-item label="">-->
      <!--      <el-upload-->
      <!--        class="upload-demo"-->
      <!--        ref="upload"-->
      <!--        action="http://127.0.0.1:10001/pdfToText/pdfToText"-->
      <!--        :on-preview="handlePreview"-->
      <!--        :on-remove="handleRemove"-->
      <!--        :http-request="httpRequest"-->
      <!--        :file-list="fileList"-->
      <!--        limit = 1-->
      <!--        :auto-upload="false">-->
      <!--        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>-->
      <!--&lt;!&ndash;        <div slot="tip" class="el-upload__tip">请上传PDF文件</div>&ndash;&gt;-->
      <!--      </el-upload>-->
      <!--      </el-form-item>-->

      <!--      <el-form-item label="">-->
      <!--        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>-->
      <!--      </el-form-item>-->
    </el-form>
    <!--列表-->
    <el-table
      size="small"
      :data="listData"
      highlight-current-row
      v-loading="loading"
      :row-key="rowKeys"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
      @selection-change="handleSelectionChange"
      ref="table"
    >
      <!--      TODO 提供下载pdf、code筛选、hash去重等功能-->
      <el-table-column
        align="center"
        v-if="select"
        type="selection"
        :reserve-selection="true"
        width="60"
      >
      </el-table-column>
      <el-table-column sortable prop="fileName" label="pdf名称" width="250">
      </el-table-column>
      <el-table-column sortable prop="tag" label="文件类别" width="100">
      </el-table-column>
      <el-table-column sortable prop="fileCode" label="pdf代码" width="200">
      </el-table-column>
      <el-table-column sortable prop="projectCode" label="项目代码" width="200">
      </el-table-column>
      <el-table-column sortable prop="filePath" label="pdf路径" width="300">
      </el-table-column>

      <el-table-column align="center" label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="showPDF(scope.row)"
            >查看pdf内容</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="deleteUser(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <!-- 编辑界面 -->
    <el-dialog
      :title="title"
      :visible.sync="editFormVisible"
      width="30%"
      @click="closeDialog"
    >
      <el-form
        label-width="120px"
        :model="editForm"
        :rules="rules"
        ref="editForm"
      >
        <el-form-item label="部门名称" prop="deptName">
          <el-input
            size="small"
            v-model="editForm.deptName"
            auto-complete="off"
            placeholder="请输入部门名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="部门代码" prop="deptNo">
          <el-input
            size="small"
            v-model="editForm.deptNo"
            auto-complete="off"
            placeholder="请输入部门代码"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="closeDialog">取消</el-button>
        <el-button
          size="small"
          type="primary"
          :loading="loading"
          class="title"
          @click="submitForm('editForm')"
          >保存</el-button
        >
      </div>
    </el-dialog>

    <!--    pdf展示页面-->
    <!-- <el-dialog title="PDF内容" :visible.sync="contentShow_" width="30%" @click="closeDialog">
      <el-form label-width="120px" :model="editForm" :rules="rules" ref="editForm">
        <ul class="infinite-list" v-infinite-scroll="load" style="overflow:auto">
          {{content}}
        </ul>
      </el-form>

    </el-dialog> -->
    <el-dialog
      custom-class="custom-dialog"
      title="PDF内容"
      :visible.sync="contentShow_"
      top="8vh"
      width="60%"
      @click="closeDialog"
    >
      <div class="dialog-content">
        <div class="top-box">
          <!-- <img :src="imageUrl" alt="PDF Thumbnail" style="width: 100%; height: auto;" /> -->
          <div class="scrollable-content">
            <!-- <pdf v-for="item in numPages" :key="item" :src="pdfSrc" :page="item" ref="pdf"></pdf> -->
            <pdf
              ref="pdf"
              :src="src"
              :page="currentPage"
              @num-pages="pageCount = $event"
              @page-loaded="currentPage = $event"
              @loaded="loadPdfHandler"
            >
            </pdf>
          </div>
          <p class="arrow" style="text-align: center">
            <!-- // 上一页 -->
            <el-button type="primary" plain @click="changePdfPage(0)"
              >上一页</el-button
            >
            {{ currentPage }} / {{ pageCount }}
            <el-button type="primary" @click="changePdfPage(1)">
              下一页
            </el-button>
            <el-button type="primary" @click="scaleD()"> 放大 </el-button>
            <el-button type="primary" @click="scaleX()"> 缩小 </el-button>
          </p>
        </div>
        <div class="bottom-box">
          <ul
              class="infinite-list"
              v-infinite-scroll="load"
              style="overflow: auto"
            >
              {{
                content
              }}
            </ul>
          <!-- <el-form
            label-width="120px"
            :model="editForm"
            :rules="rules"
            ref="editForm"
          >

          </el-form> -->
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import pdf from "vue-pdf";
import { deptList, deptSave, deptDelete } from "../../api/userMG";
import Pagination from "../../components/Pagination";
import axios from "axios";
export default {
  props: ["propName"],
  data() {
    return {
      scale: 100, //放大系数

      // imageUrl: "/static/交易订单.png", // 替换为实际的图片路径
      currentPage: 0, // pdf文件页码
      pageCount: 0, // pdf文件总页数
      fileType: "pdf", // 文件类型
      src: "/static/pdffiles/1.pdf", // pdf文件地址
      select: false,
      content: "",
      contentShow_: false,
      filename: "test",
      //old_data
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: "添加",
      editForm: {
        deptId: "",
        deptName: "",
        deptNo: "",
        token: localStorage.getItem("logintoken"),
      },
      // rules表单验证
      rules: {
        deptName: [
          { required: true, message: "请输入部门名称", trigger: "blur" },
        ],
        deptNo: [
          { required: true, message: "请输入部门代码", trigger: "blur" },
        ],
      },
      formInline: {
        page: 1,
        limit: 10,
        varLable: "",
        varName: "",
        token: localStorage.getItem("logintoken"),
        tagId: "",
      },
      // 删除部门
      seletedata: {
        ids: "",
        token: localStorage.getItem("logintoken"),
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },

      multipleSelection: [],
      typeOptions: [],
      searchTag: "",
    };
  },
  // 注册组件
  components: {
    Pagination,
    pdf,
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.select = this.$parent.$children.length == 3;
    this.getdata(this.formInline);
    this.initOptions();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    //放大
    scaleD() {
      this.scale += 5;
      this.$refs.pdf.$el.style.width = parseInt(this.scale) + "%";
      this.$refs.pdf.$el.style.height = parseInt(this.scale) + "%";
    },
    //缩小
    scaleX() {
      if (this.scale == 50) {
        return;
      }
      this.scale += -5;
      this.$refs.pdf.$el.style.width = parseInt(this.scale) + "%";
      this.$refs.pdf.$el.style.height = parseInt(this.scale) + "%";
    },
    // 改变PDF页码,val传过来区分上一页下一页的值,0上一页,1下一页
    changePdfPage(val) {
      // console.log(val)
      if (val === 0 && this.currentPage > 1) {
        this.currentPage--;
        // console.log(this.currentPage)
      }
      if (val === 1 && this.currentPage < this.pageCount) {
        this.currentPage++;
        // console.log(this.currentPage)
      }
    },
    // pdf加载时
    loadPdfHandler(e) {
      this.currentPage = 1; // 加载的时候先加载第一页
    },
    // 获取公司列表
    getdata(parameter) {
      console.log("this.params", this.formInline);

      this.loading = true;
      let url = this.$global.javaUrl + "/dataSource/listUnStruct";
      let config = {
        headers: {
          "Content-Type": "multipart/form-data",
          user: localStorage.getItem("userId"),
        },
      };
      axios
        .get(url, {
          headers: {
            user: localStorage.getItem("userId"),
          },
          params: {
            pageNum: this.formInline.page,
            pageSize: this.formInline.limit,
            tagId: this.formInline.tagId == "" ? 0 : this.formInline.tagId,
          },
        })
        .then((res) => {
          console.log("返回信息");
          console.log(res);
          this.listData = res.data.data.rows;
          console.log("fffffffff");
          console.log(res.data.data.rows.length);
          this.pageparm.currentPage = this.formInline.page;
          this.pageparm.pageSize = this.formInline.limit;
          this.pageparm.total = res.data.data.records;
        });
      // this.loading = true
      // // 模拟数据开始
      // let res = {
      //   code: 0,
      //   msg: null,
      //   count: 5,
      //   data: [
      //     {
      //       addUser: null,
      //       editUser: null,
      //       addTime: 1521062371000,
      //       editTime: 1526700200000,
      //       deptId: 2,
      //       deptName: 'XX分公司',
      //       deptNo: '1',
      //       parentId: 1
      //     },
      //     {
      //       addUser: null,
      //       editUser: null,
      //       addTime: 1521063247000,
      //       editTime: 1526652291000,
      //       deptId: 3,
      //       deptName: '上海测试',
      //       deptNo: '02',
      //       parentId: 1
      //     },
      //     {
      //       addUser: null,
      //       editUser: null,
      //       addTime: 1526349555000,
      //       editTime: 1526349565000,
      //       deptId: 12,
      //       deptName: '1',
      //       deptNo: '11',
      //       parentId: 1
      //     },
      //     {
      //       addUser: null,
      //       editUser: null,
      //       addTime: 1526373178000,
      //       editTime: 1526373178000,
      //       deptId: 13,
      //       deptName: '5',
      //       deptNo: '5',
      //       parentId: 1
      //     },
      //     {
      //       addUser: null,
      //       editUser: null,
      //       addTime: 1526453107000,
      //       editTime: 1526453107000,
      //       deptId: 17,
      //       deptName: 'v',
      //       deptNo: 'v',
      //       parentId: 1
      //     }
      //   ]
      // }
      this.loading = false;
      // this.listData = res.data
      this.pageparm.currentPage = this.formInline.page;
      this.pageparm.pageSize = this.formInline.limit;
      // 模拟数据结束

      /***
       * 调用接口，注释上面模拟数据 取消下面注释
       */
      // deptList(parameter)
      //   .then(res => {
      //     this.loading = false
      //     if (res.success == false) {
      //       this.$message({
      //         type: 'info',
      //         message: res.msg
      //       })
      //     } else {
      //       this.listData = res.data
      //       // 分页赋值
      //       this.pageparm.currentPage = this.formInline.page
      //       this.pageparm.pageSize = this.formInline.limit
      //       this.pageparm.total = res.count
      //     }
      //   })
      //   .catch(err => {
      //     this.loading = false
      //     this.$message.error('菜单加载失败，请稍后再试！')
      //   })
    },
    httpRequest(param) {
      console.log(param);
      let fileObj = param.file; // 相当于input里取得的files
      let fd = new FormData(); // FormData 对象
      fd.append("file", fileObj); // 文件对象

      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      var str = yy + "_" + mm + "_" + dd + " " + hh + "_" + mf + "_" + ss;
      fd.append("name", str);

      let url = this.$global.javaUrl + "/pdfToText/pdfToText";
      let config = {
        headers: {
          "Content-Type": "multipart/form-data",
        },
      };
      axios.post(url, fd, config).then((res) => {
        if (res.code === 0) {
          // this.submitForm();//提交表单
        }
        this.resData = res.data.data;
        this.open();
        console.log("log");
        console.log(res.data.data);
      });

      // window.location.reload();
    },
    submitUpload() {
      this.loading = true;
      this.$refs.upload.submit();
      setTimeout(function () {
        window.location.reload();
      }, 2 * 1000);
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage;
      this.formInline.limit = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.formInline.page = 1;
      this.getdata(this.formInline);
    },
    reset() {
      this.formInline.page = 1;
      this.formInline.tagId = "";
      this.getdata(this.formInline);
    },
    //显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true;
      if (row != undefined && row != "undefined") {
        this.title = "修改";
        this.editForm.deptId = row.deptId;
        this.editForm.deptName = row.deptName;
        this.editForm.deptNo = row.deptNo;
      } else {
        this.title = "添加";
        this.editForm.deptId = "";
        this.editForm.deptName = "";
        this.editForm.deptNo = "";
      }
    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      this.$refs[editData].validate((valid) => {
        if (valid) {
          deptSave(this.editForm)
            .then((res) => {
              this.editFormVisible = false;
              this.loading = false;
              if (res.success) {
                this.getdata(this.formInline);
                this.$message({
                  type: "success",
                  message: "公司保存成功！",
                });
              } else {
                this.$message({
                  type: "info",
                  message: res.msg,
                });
              }
            })
            .catch((err) => {
              this.editFormVisible = false;
              this.loading = false;
              this.$message.error("公司保存失败，请稍后再试！");
            });
        } else {
          return false;
        }
      });
    },

    showPDF(row) {
      this.content = row.content;
      let prefix = "/fagai/vue/dist";
      this.scale = 100
      //检查路径是否以指定前缀开始
      if (row.filePath.startsWith(prefix)) {
        // 移除前缀
        this.src  = row.filePath.substring(prefix.length);
      }
      this.currentPage = 1;
      this.contentShow_ = true;
      console.log("row", this.src);
    },
    // 删除公司
    deleteUser(index, row) {
      var dId = row.id;
      var filepath = row.filePath
      console.log(row)
      this.$confirm("确定要删除吗?", "信息", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let url = this.$global.javaUrl + "/dataSource/delUnStruct";
          let config = {
            headers: {
              "Content-Type": "multipart/form-data",
              user: localStorage.getItem("userId"),
            },
          };
          axios
            .get(url, {
              headers: {
                user: localStorage.getItem("userId"),
              },
              params: {
                dId: dId,
                filepath: filepath
              },
            })
            .then((res) => {
              if (res.status == 200) {
                this.$message({
                  type: "success",
                  message: "数据已删除!",
                });
                this.getdata(this.formInline);
              } else {
              }
            })
            .catch((err) => {
              this.loading = false;
              this.$message.error("数据删除失败，请稍后再试！");
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
      this.contentshow_ = false;
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    clearSelection() {
      this.multipleSelection = [];
      this.$refs.table.clearSelection();
    },
    getSelection() {
      return this.multipleSelection;
    },
    rowKeys(row) {
      return row.id;
    },
    initOptions() {
      axios
        .get(
          this.$global.javaUrl + "/modelFiletag/list?pageSize=100&pageNum=1",
          {
            headers: {
              user: localStorage.getItem("userId"),
            },
          }
        )
        .then((res) => {
          this.typeOptions = res.data.data.rows;
        });
    },
  },
};
</script>

<style scoped>

>>> .custom-dialog{
  margin-bottom: 0;
  height: 88vh;
  overflow: hidden;
}
>>>  .custom-dialog .el-dialog__body {
  overflow: hidden;
  height: 73vh;
}
.dialog-content {
  overflow: hidden;
  height: 100%;
}
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 10vh; /* 或者设置一个固定高度 */
}

/* 以下是对话框的样式内容 */

.dialog-content {
  display: flex;
  flex-direction: column;
  /* justify-content: space-between; */
  /* height: 560px; */
   /* 设置对话框内容的高度 */
}
.bottom-box {
  overflow: auto;
}

.left-column {
  flex: 2;
  padding: 10px;
  border-right: 1px solid #ccc; /* 灰色竖线 */
}

.right-column {
  flex: 1;
  padding: 10px;
  overflow-y: auto; /* 启用垂直滚动 */
}

.infinite-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.infinite-list li {
  padding: 10px;
  border-bottom: 1px solid #eee;
}
.scrollable-content {
  overflow-y: auto;
  height: 380px;
  /* height: 480px;  */
  /* 设置滚动内容的高度 */
  padding: 10px;
}

</style>


